function ajax(params) {
    if (!params.url) throw new Error('数据地址必须传输')
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest()
        params.method = params.method || 'GET'
        params.data = params.data || {}
        xhr.open(params.method, params.url)
        xhr.setRequestHeader('Content-Type', 'application/json')
        xhr.onreadystatechange = function () {
            if (this.readyState === 4) {
                if (this.status === 200) {
                    resolve(JSON.parse(this.responseText))
                } else {
                    reject({
                        code: this.status
                    })
                }
            }
        }
        xhr.send(JSON.stringify(params.data))
    })
}